%{
AUTHOR: Felipe Arteaga
-------------------------------------------------------------------------
PROJECT: Warnings
-------------------------------------------------------------------------
DESCRIPTION:

Total surveyed (intented) were  373,710

(unique id_postulantes of inputQualtrics_PILOTO merged with
inputQualtrics_SinPiloto_OnePerApod)
=========================================================================
%}


clearvars -except projectDir projectDirData fromMainWarningsPaper
clc;close all;fclose('all');feature('DefaultCharacterSet','UTF-8');

if(not(exist('projectDir','var')==1&&exist('projectDirData','var')==1&&exist('fromMainWarningsPaper','var')==1&&fromMainWarningsPaper))
    pcName=char(java.lang.System.getProperty('user.name'));
    if(strcmp(pcName,'felipe'))
        % PC Felipe
        myDir='/Users/felipe/Dropbox/';
        projectDir=[myDir,'git/warnings/'];
        projectDirData=[myDir,'projects/warnings/'];
        addpath(genpath([myDir,'/myMatlabFunctions/']));
    end
end


dirPlots=[projectDir,'/paper/figuresCL/survey2020/'];
dirTable=[projectDir,'/paper/tablesCL/'];

dirData=[projectDirData,'/data/chile/'];


anho=2020;
anhoStr=sprintf('%i',anho);

% Load survey data
% From "Mineduc/encuestas/riesgo2020/doFiles/readCleanData.do"
survey=readtable([dirData,anhoStr,'/dataEncuestaMail.csv']);


% Load compiled admin/API/interventions data
load([projectDirData,'/data/chile/',anhoStr,'/inputRD'],'dataRD');

assert(all((ismember(survey.id_postulante,dataRD.id_postulante))))


widthPlots=300;
heightPlots=200;
scalePlots=.55;
withKernelD=false;

% Merge survey data:
survey.withSurvey=true(height(survey),1);

% Fix knowledge in survey:

survey=sortrows(survey,'id_postulante');
rng(1232354)
conDos=not(ismissing(survey.knowledgeArea_BadAndCheap))&not(ismissing(survey.knowledgeArea_GoodAndExpensive));
randnum=rand(height(survey),1);

survey.knowledgeArea_Random(ismissing(survey.knowledgeArea_Random)&conDos==1&randnum<.5)=survey.knowledgeArea_BadAndCheap(ismissing(survey.knowledgeArea_Random)&conDos==1&randnum<.5);
survey.knowledgeArea_Random(ismissing(survey.knowledgeArea_Random)&conDos==1&randnum>=.5)=survey.knowledgeArea_GoodAndExpensive(ismissing(survey.knowledgeArea_Random)&conDos==1&randnum>=.5);

survey.knowledgeArea_Random(ismissing(survey.knowledgeArea_Random)&not(ismissing(survey.knowledgeArea_BadAndCheap)))=survey.knowledgeArea_BadAndCheap(ismissing(survey.knowledgeArea_Random)&not(ismissing(survey.knowledgeArea_BadAndCheap)));
survey.knowledgeArea_Random(ismissing(survey.knowledgeArea_Random)&not(ismissing(survey.knowledgeArea_GoodAndExpensive)))=survey.knowledgeArea_GoodAndExpensive(ismissing(survey.knowledgeArea_Random)&not(ismissing(survey.knowledgeArea_GoodAndExpensive)));




dataRD=outerjoin(dataRD,survey,'keys',{'id_postulante'},'mergeKeys',true,'type','left');
dataRD.completed=double(dataRD.progress==100);


if(false)
    % This is to check the selection of the answers in cantKnlowdege
    
    % Las que no tienen info en cantKnowledge es pq no están en el sample
    % de cartillas, y los filtros que ocuparon son los siguientes:
    
    
    
    
    
%  Generado en genSchoolsKnowledge.m:
load(dirBasura('schoolsAround2020'),'schoolsAround');
assert(any(schoolsAround.cantSchools2k_notInApp<schoolsAround.cantSchools2k))
assert(any(schoolsAround.cantSchools2k_notInApp==schoolsAround.cantSchools2k))

% Add cantKnowledge, to see who responded less:
load([myDir,'/Mineduc/encuestas/riesgo2020/dataInput/dataIntermediateSchoolsKnowledge'],'dataInput');
dataRD=outerjoin(dataRD,dataInput,'keys',{'id_postulante',},'mergeKeys',true,'type','left','rightVariables',{'cantKnowledge','typeKnowledge1','typeKnowledge2','typeKnowledge3','typeKnowledge4','typeKnowledge5'});
dataRD=outerjoin(dataRD,schoolsAround,'keys',{'id_postulante',},'mergeKeys',true,'type','left');
%%

type=3; %Random
dataRD.conRandom=double(dataRD.typeKnowledge1==type|dataRD.typeKnowledge2==type|dataRD.typeKnowledge3==type|dataRD.typeKnowledge4==type|dataRD.typeKnowledge5==type);
dataRD.conRandom(isnan(dataRD.cantKnowledge))=nan;

dataRD.postulaTodos=dataRD.cantSchools2k>0&dataRD.cantSchools2k_notInApp==0;
dataRD.sinColes2k=dataRD.cantSchools2k==0;
dataRD.sinData=isnan(dataRD.cantSchools2k);

dataRD.cat=2*dataRD.postulaTodos+1*dataRD.sinColes2k+3*dataRD.sinData;
dataRD.cat=categorical(dataRD.cat,[1 2 3],{'No schools','Apply to all','No info'});

raros=dataRD.conRandom==0&ismissing(dataRD.cat);
tabflow(dataRD.conRandom(dataRD.withSurvey==1),dataRD.cat(dataRD.withSurvey==1),'precisionCondPerc','%3.3f')


%Only big markets
dataRD.bigMarket=getDigit(dataRD.newMarket,1:3)==1;

tabflow(dataRD.conRandom(dataRD.withSurvey==1&dataRD.bigMarket),dataRD.cat(dataRD.withSurvey==1&dataRD.bigMarket),'precisionCondPerc','%3.3f')

end





%% Data modifications and new vars

missingEduM=sum(ismissing(dataRD.educMother));
dataRD.educMother=categorical(dataRD.educMother,{'Didn''t study','Incomplete Elementary Education','Complete Elementary Education','Incomplete High School','Complete High School','Licensed from a Technical Training Center or a Professional Institute','Incomplete University Education','Licensed from University','Masters Degree'},'ordinal',true);
assert(sum(ismissing(dataRD.educMother))==missingEduM)


dataRD.probPlacedAny_inverted=1-dataRD.probPlacedAny;
dataRD.probNoPlaced_inverted=1-dataRD.probNoPlaced;

% Merge declared risk (positive and negative version):
dataRD.declaredRisk=dataRD.probNoPlaced;
dataRD.declaredRisk(not(isnan(dataRD.probPlacedAny)))=1-dataRD.probPlacedAny(not(isnan(dataRD.probPlacedAny)));

% Risk using unconditional probabilities (only 1 2 and 3)
dataRD.declaredImplicitRisk=nan(height(dataRD),1);
dataRD.declaredImplicitRisk(dataRD.lengthEnd==1)=1-dataRD.probPlaced1st(dataRD.lengthEnd==1);
dataRD.declaredImplicitRisk(dataRD.lengthEnd==2)=(1-dataRD.probPlaced1st(dataRD.lengthEnd==2)).*(1-dataRD.probPlaced2ndAs1st(dataRD.lengthEnd==2));
dataRD.declaredImplicitRisk(dataRD.lengthEnd==3)=(1-dataRD.probPlaced1st(dataRD.lengthEnd==3)).*(1-dataRD.probPlaced2ndAs1st(dataRD.lengthEnd==3)).*(1-dataRD.probPlaced3rdAs1st(dataRD.lengthEnd==3));

% Categorical versions of risk
dataRD.riskRealCat=discretize(dataRD.riskExpostEnd,[0,.01,.3,.7 1],'categorical');
dataRD.riskDeclaredCat=discretize(dataRD.declaredRisk,[0,.01,.3,.7 1],'categorical');

dataRD.receivedRecommendationAddMore=categorical(dataRD.receivedRecommendationAddMore);
dataRD.receiveWarning=double(dataRD.receivedRecommendationAddMore=='Yes');
dataRD.receiveWarning(ismissing(dataRD.receivedRecommendationAddMore))=nan;


dataRD.reasonNotAddingMore=categorical(dataRD.reasonNotAddingMore);
oldCats={'I know the other options well and I prefer to be without a school than to add those alternatives','I think they will be admitted in the ones I applied','It is very difficult to find more schools.','There are no more schools close enough (good or bad)'};
newCats={'I rather not have placement','I think I will be placed','It''s very hard to find more','No more schools around'};
dataRD.reasonNotAddingMore2=renamecats(dataRD.reasonNotAddingMore,oldCats,newCats);


dataRD.lengthEndCat=dataRD.lengthEnd;
dataRD.lengthEndCat(dataRD.lengthEndCat>6)=6;
dataRD.lengthEndCat=categorical(dataRD.lengthEndCat,'ordinal',true);
dataRD.lengthEndCat = renamecats(dataRD.lengthEndCat,{'6'},{'6+'});

dataRD.probAddUnknownSchool1stCat=discretize(dataRD.probAddUnknownSchool1st/100,0:.2:1,'categorical');
dataRD.probAddUnknownSchoolLastCat=discretize(dataRD.probAddUnknownSchoolLast/100,0:.2:1,'categorical');

% Labels:
dataRD.Properties.VariableDescriptions{'lengthEndCat'}='Length of application';
dataRD.Properties.VariableDescriptions{'receiveWarning'}='Declare that received recomendation to add more';
dataRD.Properties.VariableDescriptions{'probAddUnknownSchool1stCat'}='Prob add unknown 1st';
dataRD.Properties.VariableDescriptions{'probAddUnknownSchoolLastCat'}='Prob add unknown last';

vars=dataRD.Properties.VariableNames;

%% Categorize some:
% Make levels of knowledge numbers:
catsPast={'I didn''t know it before appl.','I knew it by name before appl.','I knew it well before appl.'};
catsPresent={'I don''t know it','I know it by name','I know it well'};

varsAdd=vars(startsWith(vars,'knowledgeAdd'));
varsApp=vars(startsWith(vars,'knowledgeApp')|startsWith(vars,'knowledgeArea'));

for v=1:length(varsAdd)
    auxCount=sum(ismissing(dataRD.(varsAdd{v})));
    dataRD.(varsAdd{v})=categorical(dataRD.(varsAdd{v}),catsPast,'ordinal',true);
    assert(sum(ismissing(dataRD.(varsAdd{v})))==auxCount)
end

for v=1:length(varsApp)
    auxCount=sum(ismissing(dataRD.(varsApp{v})));
    dataRD.(varsApp{v})=categorical(dataRD.(varsApp{v}),catsPresent,'ordinal',true);
    assert(sum(ismissing(dataRD.(varsApp{v})))==auxCount)
end

%% New satisf
cats=[0 4 7 7];
labelsCats={'Non satisfied ($<$4)','Satisfied (4 to 6)','Very satisfied (7)'};
dataRD.satisf_1_cat=discretize(dataRD.satisf_1,cats,'Categorical',labelsCats,'includedEdge','left');
dataRD.satisf_last_cat=discretize(dataRD.satisf_last,cats,'Categorical',labelsCats,'includedEdge','left');
dataRD.satisf_noPlace_cat=discretize(dataRD.satisf_noPlace,cats,'Categorical',labelsCats,'includedEdge','left');

dataRD.Properties.VariableDescriptions{'satisf_1_cat'}='If placed in 1st';
dataRD.Properties.VariableDescriptions{'satisf_last_cat'}='If placed in last';
dataRD.Properties.VariableDescriptions{'satisf_noPlace_cat'}='If not placed';

%% Some labels to original vars


dataRD.Properties.VariableDescriptions{'satisf_1'}='Satisfaction if placed in 1st';
dataRD.Properties.VariableDescriptions{'satisf_last'}='Satisfaction if placed in last';
dataRD.Properties.VariableDescriptions{'satisf_noPlace'}='Satisfaction if not placed';


dataRD.Properties.VariableDescriptions{'newinfo_acceptanceprob'}='Admission chances';
dataRD.Properties.VariableDescriptions{'newinfo_vacant'}='Vacancies';
dataRD.Properties.VariableDescriptions{'newinfo_simce'}='Standarized test score';
dataRD.Properties.VariableDescriptions{'newinfo_performance'}='Performance category';
dataRD.Properties.VariableDescriptions{'newinfo_psu'}='College admission test score';
dataRD.Properties.VariableDescriptions{'newinfo_fee'}='Fees';
dataRD.Properties.VariableDescriptions{'newinfo_sep'}='Scholarship eligibility';

orderNewInfo={'newinfo_acceptanceprob','newinfo_vacant'};
orderNewInfo_all={'newinfo_acceptanceprob','newinfo_vacant','newinfo_simce','newinfo_performance','newinfo_psu','newinfo_fee','newinfo_sep'};

noteDescInfo='''Performance category'': comprehensive quality categorization developed by a public agency (Agencia de la Calidad de la Educación) that takes into account different socioeconomic contexts.';

dataRD.Properties.VariableDescriptions{'step_infra'}='Info. on infrastructure';
dataRD.Properties.VariableDescriptions{'step_interview'}='Interview w/staff';
dataRD.Properties.VariableDescriptions{'step_web'}='Visit school''s website';
dataRD.Properties.VariableDescriptions{'step_ref'}='Ask for references';
dataRD.Properties.VariableDescriptions{'step_perf'}='Info. on academic performance';
dataRD.Properties.VariableDescriptions{'step_agency'}='Info. from Quality Assurance Institution';
dataRD.Properties.VariableDescriptions{'step_extra'}='Info. on extracurricular activities';
dataRD.Properties.VariableDescriptions{'step_pie'}='Info. on educational mission'; % Es PEI no PIE! (PEI: proyecto educacional institucional)
dataRD.('step_web2')=[]; % Repetida!


dataRD.Properties.VariableDescriptions{'knowledgeAdd1'}='1st added';
dataRD.Properties.VariableDescriptions{'knowledgeAdd2'}='2nd added';
dataRD.Properties.VariableDescriptions{'knowledgeAdd3'}='3rd added';

dataRD.Properties.VariableDescriptions{'knowledgeApp1'}='1st';
dataRD.Properties.VariableDescriptions{'knowledgeApp2'}='2nd';
dataRD.Properties.VariableDescriptions{'knowledgeApp3'}='3rd';
dataRD.Properties.VariableDescriptions{'knowledgeApp4'}='4th';
dataRD.Properties.VariableDescriptions{'knowledgeApp5'}='5th';



dataRD.Properties.VariableDescriptions{'knowledgeArea_Fake'}='Fake school';
dataRD.Properties.VariableDescriptions{'knowledgeArea_BadAndCheap'}='Low Perf. and Free';
dataRD.Properties.VariableDescriptions{'knowledgeArea_GoodAndExpensive'}='High Perf and Expensive';
dataRD.Properties.VariableDescriptions{'knowledgeArea_Random'}='Random within area';


noteSteps='''Info from ''Agencia'': Information generated by ``Agencia de la Calidad de la Educación''''';

%% Check is there is knowledge gain
% If schools were in "added" and in "application", then we might have the
% knowledge before application and after application.


matrixRbdAdd=table2array(dataRD(:,vars(startsWith(vars,'rbdAdd'))));
matrixRbdApp=table2array(dataRD(:,vars(startsWith(vars,'rbdApp'))));

matrixKnowAdd=double(table2array(dataRD(:,vars(startsWith(vars,'knowledgeAdd')))));
matrixKnowApp=double(table2array(dataRD(:,vars(startsWith(vars,'knowledgeApp')))));

matrixDeltaKnow=nan(size(matrixRbdAdd));
matrixDeltaRbd=nan(size(matrixRbdAdd)); % this is only for checking that I'm not doing stupid stuff.


for i=find(dataRD.withSurvey')
    [addInApp,pos]=ismember(matrixRbdAdd(i,:),matrixRbdApp(i,:));
    if(any(addInApp))
        addInAppPos=find(addInApp);
        for j=1:length(addInAppPos)
            
            matrixDeltaKnow(i,addInAppPos(j))=matrixKnowApp(i,pos(j))-matrixKnowAdd(i,addInAppPos(j));
            matrixDeltaRbd(i,addInAppPos(j))=matrixRbdApp(i,pos(j))-matrixRbdAdd(i,addInAppPos(j));
        end    
    end
end
assert(all(matrixDeltaRbd==0|isnan(matrixDeltaRbd),'all'))

dataRD.deltaKnowAdd1=matrixDeltaKnow(:,1);
dataRD.deltaKnowAdd2=matrixDeltaKnow(:,2);
dataRD.deltaKnowAdd3=matrixDeltaKnow(:,3);



catsValues=[-2 -1 0 1 2];
catsLabels={'Less than pre-application','Less than pre-application','Same','More than pre-application','More than pre-application'};

dataRD.deltaKnowAddCat1=categorical(dataRD.deltaKnowAdd1,catsValues,catsLabels);
dataRD.deltaKnowAddCat2=categorical(dataRD.deltaKnowAdd2,catsValues,catsLabels);
dataRD.deltaKnowAddCat3=categorical(dataRD.deltaKnowAdd3,catsValues,catsLabels);

dataRD.Properties.VariableDescriptions{'deltaKnowAddCat1'}='1st added';
dataRD.Properties.VariableDescriptions{'deltaKnowAddCat2'}='2nd added';
dataRD.Properties.VariableDescriptions{'deltaKnowAddCat3'}='3rd added';

% Hay muchos que agregan colegios pero no les puedo calcular ganacia en
% knowledge:
% 1) Pq no llegan a esa pregunta (progress<<100)
% 2) Pq agregan más de 3, y a esos no les estamo preguntando si los conocia
% de antes :(


%% Do the plots!


vars=dataRD.Properties.VariableNames;

colors=linspecer(2);

%%
for s=2:2
    switch s
        case 1
            sirven=dataRD.riskExpostEnd>.01; %&dataRD.educMother>'Complete High School'
            sufix='_risky';
        case 2
            sirven=true(height(dataRD),1);
            sufix='_all';
    end
            
   
close all

%% APPENDIX  (It was 1a, now goes to appendix)
figCell=cell(1,2);
figure
barmultipleBinaria(dataRD,orderNewInfo,'Yes','Fraction','horizontal',true)
xtickangle(60)
note=sprintf('N: %i. %s',sum(not(ismissing(dataRD.(orderNewInfo{1})))),noteDescInfo);
figCell{1,1}=easyExport([dirPlots,'surv_newInfo',sufix],'displayLatex',true,'caption','Information that would have liked to have but you did not have.','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);


figure
text(0.5,0.5,'NH plot')
figCell{1,2}=easyExport([dirPlots,'surv_nh',sufix],'displayLatex',true,'caption','Info NH','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);
subfiguresLatex(figCell,'caption','Demand for information','label','figDemandInfoAppendix','file',[dirPlots,'figDemandInfoAppendix.tex'],'scale',scalePlots,'erpf','figuresCL/survey2020/');

% This is for beamer
figure
barmultipleBinaria(dataRD,orderNewInfo_all,'Yes','Fraction','horizontal',true)
note=sprintf('N: %i. %s',sum(not(ismissing(dataRD.(orderNewInfo{1})))),noteDescInfo);
figCell{1,1}=easyExport([dirPlots,'surv_newInfo_all',sufix],'displayLatex',true,'caption','Chile: Information that would have liked to have but you did not have.','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);

% This is NH made by hand  (from info_pref_pooled.png) 
figure
dataNH=[.774 .832 .835 .85 .858 .902];
labelsNH={'Earlier outreach','Bus routes','School suggestions','Priorities','Notifications','Admission chances'};
tableNH=table;
for nhv=1:6
tableNH.(sprintf('v%i',nhv))=zeros(1000,1);
tableNH.(sprintf('v%i',nhv))(1:round(dataNH(nhv)*1000))=1;
tableNH.Properties.VariableDescriptions{sprintf('v%i',nhv)}=labelsNH{nhv};
end
nhVars=tableNH.Properties.VariableNames;
barmultipleBinaria(tableNH,nhVars,1,'Fraction','horizontal',true)

figCell{1,2}=easyExport([dirPlots,'surv_infoNH',sufix],'displayLatex',true,'caption','New Haven: Information that would be most helpful for future applicants.','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);
subfiguresLatex(figCell,'caption','Demand for information','label','figDemandInfoAppendix','file',[dirPlots,'figDemandInfo_all.tex'],'scale',scalePlots,'erpf','figuresCL/survey2020/');


%% 2A) to 2C) to appendix
%% 2a)
figCell=cell(2,2);

figure
varsPlot=vars(startsWith(vars,'step'));
barmultipleBinaria(dataRD,varsPlot,'Necessary','Fraction','horizontal',true)
%xtickangle(60)
note=sprintf('N: %i. %s',sum(not(ismissing(dataRD.(varsPlot{1})))),noteSteps);
figCell{1,1}=easyExport([dirPlots,'surv_relevantSteps',sufix],'displayLatex',true,'caption','Necessary aspect to get to know well a school before applying','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);


%% 2b) baseline knowledge of added schools

figure
varsPlot=vars(startsWith(vars,'knowledgeAdd'));
barmultiple(dataRD,varsPlot,'wnb',0)
note=sprintf('N: %i.',sum(not(ismissing(dataRD.(varsPlot{1})))));
figCell{1,2}=easyExport([dirPlots,'surv_knowAdd',sufix],'displayLatex',true,'caption','Knowledge of added schools before application process','updatelegend',true,'includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

%% 2b2) baseline knowledge of applied schools



figure
varsPlot=vars(startsWith(vars,'knowledgeApp'));
barmultiple(dataRD,varsPlot,'wnb',0)
note=sprintf('N: %i.',sum(not(ismissing(dataRD.(varsPlot{1})))));
figCell{1,2}=easyExport([dirPlots,'surv_knowApp',sufix],'displayLatex',true,'caption','Knowledge of applied schools','updatelegend',true,'includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);






%% 2c) Gain in knowledge of added schools (how best to display this?)


varsPlot=vars(startsWith(vars,'deltaKnowAddCat'));
figure
barmultiple(dataRD,varsPlot,'wnb',false)
note=sprintf('N: %i.',sum(not(ismissing(dataRD.(varsPlot{1})))));
figCell{2,1}=easyExport([dirPlots,'surv_KnowledgeGain',sufix],'displayLatex',true,'caption','Comparison of knowledge of added school before and after application','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',true,'note',note);


subfiguresLatex(figCell,'caption','Knowledge about listed options','label','figLearningAppendix','file',[dirPlots,'figLearningAppendix.tex'],'scale',scalePlots,'erpf','figuresCL/survey2020/');
%% 2d) knowledge of other schools in area (only knowWell)
figCell=cell(2,2);
figure
colorsGrayProof=linspecerGrayproof(3,'dispersion',.2);
varsPlot=vars(startsWith(vars,'knowledgeArea_'));
barmultipleBinaria(dataRD,varsPlot,'I know it well','Fraction "I know it well"','horizontal',true,'colorBar',colorsGrayProof(3,:))
note=sprintf('N: %i.',sum(not(ismissing(dataRD.(varsPlot{1})))));
figCell{1,1}=easyExport([dirPlots,'surv_knowArea',sufix],'displayLatex',true,'caption','Knowledge of other schools in area that were not included on the application','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);


% Knowledge of other schools if from bigMarket (that <1% applied to all
% schools)
dataRD.bigMarket=getDigit(dataRD.newMarket,1:3)==1;

figure
colorsGrayProof=linspecerGrayproof(3,'dispersion',.2);
varsPlot=vars(startsWith(vars,'knowledgeArea_'));
barmultipleBinaria(dataRD(dataRD.bigMarket,:),varsPlot,'I know it well','Fraction "I know it well"','horizontal',true,'colorBar',colorsGrayProof(3,:))
note=sprintf('N: %i.',sum(not(ismissing(dataRD.(varsPlot{1})))));
easyExport([dirPlots,'surv_knowArea_bigMarket',sufix],'displayLatex',true,'caption','Knowledge of other schools in area that were not included on the application','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);

%% 2e)	Panel E: Reasons for not adding more schools (fraction saying yes)

figure
histAux=histogram(dataRD.reasonNotAddingMore2(not(ismissing(dataRD.reasonNotAddingMore2))),'Normalization','probability','orientation','horizontal');
percs=histAux.Values;
colorPerc=1*[1 1 1];
%xtickangle(60)
histAux.EdgeColor='none';
for i=1:length(percs)
    if(percs(i)>.1)
        annotation2('textbox',[percs(i)/2,i],'o','String',sprintf('%2.0f$\\%%$',percs(i)*100),'Interpreter','latex','edgecolor','none','color',colorPerc)
    end
end
note=[sprintf('N: %i.',sum(not(ismissing(dataRD.reasonNotAddingMore2)))),...
    '*: ``I know the other options well and I prefer to be left without a school than to add those alternatives'''''];
    set(gca,'xTick',[]);
    xlabel('Fraction')
figCell{1,2}=easyExport([dirPlots,'surv_reasonNotAdding',sufix],'displayLatex',true,'caption','Reason did not add more schools','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);

%% 2f)  Binscatter (maybe just use current categories?) with share reporting “I think I will be admitted to one of the schools I will apply to” on vertical axis, subjective nonplacement risk assessment on the horizontal axis


figure
aux=double(dataRD.reasonNotAddingMore=='I think they will be admitted in the ones I applied');
aux(ismissing(dataRD.reasonNotAddingMore))=nan;
binsreg(1-dataRD.declaredRisk,aux,'wlf',true,'modifyxticks',false)%,'binstrategy','equally-spaced'
%binsreg(1-dataRD.declaredRisk,aux,'wlf',true,'modifyxticks',false,'withHistogram',true,'binstrategy','equally-spaced')%,'binstrategy','equally-spaced'

xlabel('Subjective placement probability')
ylabel('\% answererd ''I think I will be placed''')
ylim([0 .65])
note=sprintf('N: %i.',sum(not(ismissing(dataRD.reasonNotAddingMore))));

figCell{2,1}=easyExport([dirPlots,'surv_binsregReasonNoAddDeclRisk',sufix],'displayLatex',true,'caption','Binscatter of share answered "I will be placed" vs subjective risk','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',false,'note',note);

%% 2g)  Satisfaction 


figure
varsPlot={'satisf_noPlace_cat','satisf_last_cat','satisf_1_cat'};
barSatis=barmultiple(dataRD,varsPlot,'wnb',false,'horizontal',true,'thresholdAnnotation',.07);


note=sprintf('N: %s.',mat2cellstr(sum(not(ismissing(dataRD.satisf_noPlace_cat))),'rc',true));
easyExport([dirPlots,'surv_barSatisfaction',sufix],'displayLatex',true,'caption','"How satisfied would you be if placed in:"','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'updatelegend',true,'note',note);




%% 3A 	Panel A: histogram of *subjective* and *actual* non-placement risk
figCell=cell(3,2);

figure
sirven=not(ismissing(dataRD.declaredRisk))&dataRD.riskExpostEnd>.01;
compareHistograms({1-dataRD.declaredRisk(sirven),...
    1-dataRD.riskExpostEnd(sirven)},...
    'varlabels',{'Subjective','True'},'forceCoefPosFactor',.7)
xlabel('Placement probability')
note=sprintf('N: %i.',sum(not(ismissing(dataRD.declaredRisk(sirven)))));
figCell{1,1}=easyExport([dirPlots,'histNoPlacedVsReal',sufix],'displayLatex',false,'caption','Distribution of subjective and true placement chances','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 3B  histogram of (subjective risk-actual risk)



figure
compareHistograms({dataRD.riskExpostEnd(sirven)-dataRD.declaredRisk(sirven)},...
    'binedges',-1.05:.1:1.05)
xlabel('Optimism (subjective - true placement prob.)')

yLim=ylim;
%legendStr=get(legend,'String');

arrowr = annotation('arrow') ;
arrowr.Parent = gca;
arrowr.Position = [0, yLim(2)*.25, .2, 0] ;
hold on
plot([0 0],[0 yLim(2)],'linestyle','--','color',.5*[1 1 1]);

textr = annotation('textbox','String','Optimists','Interpreter','latex','verticalAlignment','middle','edgecolor','none') ;
textr.Parent = gca;
textr.Position = [0, yLim(2)*.3, 1, 0] ;
textr.HorizontalAlignment='left';

%legend(legendStr(1:2))
%set(legend,'String',legendStr(1:2));
hold off

note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpostEnd(sirven)-dataRD.declaredRisk(sirven)))));

figCell{1,2}=easyExport([dirPlots,'histOptimism',sufix],'displayLatex',false,'caption','Optimism','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

%% Female vs male applicants: histogram of (subjective risk-actual risk)


figure
compareHistograms({dataRD.riskExpostEnd(sirven&dataRD.female==1)-dataRD.declaredRisk(sirven&dataRD.female==1),dataRD.riskExpostEnd(sirven&dataRD.female==0)-dataRD.declaredRisk(sirven&dataRD.female==0)},...
    'binedges',-1.05:.1:1.05,'labels',{'Female appl.','Male appl.'})
xlabel('Optimism (subjective - true placement prob.)')

yLim=ylim;
%legendStr=get(legend,'String');

arrowr = annotation('arrow') ;
arrowr.Parent = gca;
arrowr.Position = [0, yLim(2)*.25, .2, 0] ;
hold on
plot([0 0],[0 yLim(2)],'linestyle','--','color',.5*[1 1 1]);

legend({'Female appl.','Male appl.'},'location','northwest')
textr = annotation('textbox','String','Optimists','Interpreter','latex','verticalAlignment','middle','edgecolor','none') ;
textr.Parent = gca;
textr.Position = [0, yLim(2)*.3, 1, 0] ;
textr.HorizontalAlignment='left';

%legend(legendStr(1:2))
%set(legend,'String',legendStr(1:2));
hold off

note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpostEnd(sirven)-dataRD.declaredRisk(sirven)))));

easyExport([dirPlots,'histOptimism_bySex',sufix],'displayLatex',false,'caption','Optimism','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);




%% 3C  Binscatter of risk belief (pooled) on actual risk

figure
br1=binsreg(1-dataRD.riskExpostEnd(sirven),1-dataRD.declaredRisk(sirven),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
ylabel('Subjective placement probability')
xlabel('True placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.declaredRisk(sirven)))));

figCell{2,1}=easyExport([dirPlots,'binsregDeclaredRealRisk',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true placement chances','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 3C.2  Binscatter of risk belief (pooled) on actual risk AND pred on real
% Not only mean, also dispertion:
figure


% Fit for all the fit
sirvenSurvey=not(ismissing(dataRD.declaredRisk))&dataRD.pobPopup==1;
sirvenSurvey2=sirvenSurvey&dataRD.riskExpostEnd>0.01;
edges=[quantile(1-dataRD.riskExpostEnd(sirvenSurvey2),10) 0.99 1];
assert(sum(edges==0)==1)
preB=discretize(1-dataRD.riskExpostEnd(sirvenSurvey),edges,'includedEdge','left');


br1=binsreg(1-dataRD.riskExpostEnd(sirvenSurvey),1-dataRD.declaredRisk(sirvenSurvey),'wlf',true,'colorall',colors(1,:),'marker','o','posCoeffFit',[.2 .57 .1 .1],'modifyXTicks',false,'wiq',true,'preb',preB,'binStrategy','custom');
hold on 
br2=binsreg(1-dataRD.riskExpostEnd(sirvenSurvey),1-dataRD.riskApiEnd(sirvenSurvey),'wlf',true,'colorall',colors(2,:),'marker','x','posCoeffFit',[.6 .4 .1 .1],'modifyXTicks',false,'wiq',true,'preb',preB,'binStrategy','custom');



ylabel('Placement probability')
xlabel('True placement probability')


hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
%set(gca,'xgrid','on')

legend([br1.scatter,br2.scatter,br1.quantileArea,br2.quantileArea],{'Subjective','Predicted','Interquartile range','Interquartile range'},'Location','southeast','Interpreter','latex')

note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.declaredRisk(sirven)))));

easyExport([dirPlots,'binsregDeclaredPredictedRealRisk',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true placement chances','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

%% Same, but only subjective

figure

sirvenSurvey=not(ismissing(dataRD.declaredRisk))&dataRD.pobPopup==1;
sirvenSurvey2=sirvenSurvey&dataRD.riskExpostEnd>0.01;
edges=[quantile(1-dataRD.riskExpostEnd(sirvenSurvey2),10) 0.99 1];
assert(sum(edges==0)==1)
preB=discretize(1-dataRD.riskExpostEnd(sirvenSurvey),edges,'includedEdge','left');


% Fit for all the fit
sirvenSurvey=not(ismissing(dataRD.declaredRisk))&dataRD.pobPopup==1;
b=binsreg(1-dataRD.riskExpostEnd(sirvenSurvey),1-dataRD.declaredRisk(sirvenSurvey),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.2 .57 .1 .1],'modifyXTicks',false,'wiq',true,'preB',preB,'binStrategy','custom');

ylabel('Subjective placement probability')
xlabel('True placement probability')


hold on
pl=plot([0 1],[0 1],'k:');
xlim([0 1])
ylim([0 1])
%set(gca,'xgrid','on')

legend([b.scatter,b.linearFitPlot,pl,b.quantileArea],{'Bin mean','Linear fit','$45^{\circ}$','Interquartile range'},'Location','southeast','Interpreter','latex')


easyExport([dirPlots,'binsregDeclaredRealRisk',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true placement chances','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);



%% 3D binscatter of *predicted risk* (vertical axis) on *actual risk (horizontal axis)
figure 

sirvenIni=dataRD.pobPopup==1&dataRD.riskExpostIni>.01;
br1=binsreg(1-dataRD.riskExpostIni(sirvenIni),1-dataRD.riskPopup(sirvenIni),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);

xlabel('True placement probability')
ylabel('Predicted placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

easyExport([dirPlots,'binsregPredictedRealRisk',sufix],'displayLatex',false,'caption','Binscatter of predicted vs true risk','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.riskPopup(sirvenIni)))));

%% 3E Binscatter of risk belief vs risk with calculated with beliefs unconditional probabilites 

figure
sirven=not(ismissing(dataRD.declaredRisk))&not(ismissing(dataRD.declaredImplicitRisk))&dataRD.riskExpostEnd>.01;
br1=binsreg(1-dataRD.declaredRisk(sirven),1-dataRD.declaredImplicitRisk(sirven),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
xlabel('Subjective placement probability')
ylabel('Subjective-implicit placement prob.')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

note=sprintf('N: %i. Only respondents with positive risk. Implicit placement probability refers to the placemnet probability calculated with the beliefs over the conditional individual probabilities (ex: Probability you will be place in second opt. if applied as first',sum(not(ismissing(1-dataRD.declaredImplicitRisk(sirven)))));

easyExport([dirPlots,'binsregImplicitDeclared',sufix],'displayLatex',false,'caption','Binscatter of subjective-implicit vs subjective placement chances','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);



%% PANEL FIGURES
%% 4A 	Panel A: histogram of *subjective* and *actual* 1st option
figCell=cell(2,2);

figure
sirven=not(ismissing(dataRD.probPlaced1st))&dataRD.riskExpostEnd>.01;
compareHistograms({dataRD.probPlaced1st(sirven),...
    1-dataRD.riskExpost_1stPrefEnd(sirven)},...
    'labels',{'Subjective','True'},'colors',[colors(1,:);.5*[1 1 1]],'forceCoefPosFactor',.7)
xlabel('1st choice placement probability')
note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpost_1stPrefEnd(sirven)))));
figCell{1,1}=easyExport([dirPlots,'histNoPlacedVsReal_1st',sufix],'displayLatex',false,'caption','Subjective and true first-choice placement probability','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 4B  histogram of (subjective risk-actual risk) 1st option



figure
compareHistograms({dataRD.riskExpost_1stPrefEnd(sirven)-(1-dataRD.probPlaced1st(sirven))},...
    'colors',colors,'binedges',-1.05:.1:1.05)
xlabel('Optimism (Subjective - true prob. placed 1st)')

yLim=ylim;
%legendStr=get(legend,'String');

arrowr = annotation('arrow') ;
arrowr.Parent = gca;
arrowr.Position = [0, yLim(2)*.25, .2, 0] ;
hold on
plot([0 0],[0 yLim(2)],'linestyle','--','color',.5*[1 1 1]);

textr = annotation('textbox','String','Optimists','Interpreter','latex','verticalAlignment','middle','edgecolor','none') ;
textr.Parent = gca;
textr.Position = [0, yLim(2)*.3, 1, 0] ;
textr.HorizontalAlignment='left';

%legend(legendStr(1:2))
%set(legend,'String',legendStr(1:2));
hold off

note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpost_1stPrefEnd(sirven)-dataRD.probPlaced1st(sirven)))));

figCell{1,2}=easyExport([dirPlots,'histOptimism_1st',sufix],'displayLatex',false,'caption','Optimism over chances of 1st choice','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 4C  Binscatter of risk belief (pooled) on actual risk 1st option

figure
br1=binsreg(1-dataRD.riskExpost_1stPrefEnd(sirven),dataRD.probPlaced1st(sirven),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
ylabel('Subjective 1st-choice placement prob.')
xlabel('True 1st-choice placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

note=sprintf('N: %i.',sum(not(ismissing(dataRD.probPlaced1st(sirven)))));

figCell{2,1}=easyExport([dirPlots,'binsregDeclaredRealRisk_1st',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true first-choice placement probability','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

%% 4D binscatter of *predicted risk* (vertical axis) on *actual risk (horizontal axis) 1st option
figure 

sirvenIni=dataRD.pobPopup==1&dataRD.riskExpostIni>.01;
br1=binsreg(1-dataRD.riskExpost_1stPrefEnd(sirvenIni),1-dataRD.riskApi_1stPrefEnd(sirvenIni),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
ylabel('Predicted first-choice placement prob.')
xlabel('True first-choice placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')
note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.riskApi_1stPrefEnd(sirvenIni)))));

figCell{2,2}=easyExport([dirPlots,'binsregPredictedRealRisk_1st',sufix],'displayLatex',false,'caption','Binscatter of predicted vs true first-choice placement probability','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


subfiguresLatex(figCell,'caption','Subjective, predicted and true first-choice probability (only applicants with positive true risk)','label','figRisks_1st','file',[dirPlots,'figRisks_1st.tex'],'scale',scalePlots,'erpf','figuresCL/survey2020/');

%% 5A 	Panel A: histogram of *subjective* and *actual* non-placement risk. NEGATIVE
figCell=cell(3,2);

figure
sirven=not(ismissing(dataRD.probNoPlaced))&dataRD.riskExpostEnd>.01;
compareHistograms({1-dataRD.probNoPlaced(sirven),...
    1-dataRD.riskExpostEnd(sirven)},...
    'labels',{'Subjective','True'},'colors',[colors(1,:);.5*[1 1 1]],'forceCoefPosFactor',.7)
xlabel('Placement probability')
note=sprintf('N: %i.',sum(not(ismissing(dataRD.probNoPlaced(sirven)))));
figCell{1,1}=easyExport([dirPlots,'histNoPlacedVsReal_neg',sufix],'displayLatex',false,'caption','Subjective and true placement (asking for risk)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 5B  histogram of (subjective risk-actual risk) NEGATIVE



figure
compareHistograms({dataRD.riskExpostEnd(sirven)-dataRD.probNoPlaced(sirven)},...
    'colors',colors,'binedges',-1.05:.1:1.05)
xlabel('Optimism (Subjective - true placement prob.)')

yLim=ylim;
%legendStr=get(legend,'String');

arrowr = annotation('arrow') ;
arrowr.Parent = gca;
arrowr.Position = [0, yLim(2)*.25, .2, 0] ;
hold on
plot([0 0],[0 yLim(2)],'linestyle','--','color',.5*[1 1 1]);

textr = annotation('textbox','String','Optimists','Interpreter','latex','verticalAlignment','middle','edgecolor','none') ;
textr.Parent = gca;
textr.Position = [0, yLim(2)*.3, 1, 0] ;
textr.HorizontalAlignment='left';

%legend(legendStr(1:2))
%set(legend,'String',legendStr(1:2));
hold off

note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpostEnd(sirven)-dataRD.probNoPlaced(sirven)))));

figCell{2,1}=easyExport([dirPlots,'histOptimism_neg',sufix],'displayLatex',false,'caption','Optimism (asking for risk)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 5C  Binscatter of risk belief (pooled) on actual risk NEGATIVE

figure
br1=binsreg(1-dataRD.riskExpostEnd(sirven),1-dataRD.probNoPlaced(sirven),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
ylabel('1-(Subjective placement risk)')
xlabel('True placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.probNoPlaced(sirven)))));

figCell{3,1}=easyExport([dirPlots,'binsregDeclaredRealRisk_neg',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true placement chances (asking for risk)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

%% 5D 	Panel A: histogram of *subjective* and *actual* non-placement risk. POSITIVE

figure
sirven=not(ismissing(dataRD.probPlacedAny_inverted))&dataRD.riskExpostEnd>.01;
compareHistograms({dataRD.probPlacedAny_inverted(sirven),...
    dataRD.riskExpostEnd(sirven)},...
    'labels',{'Subjective','True'},'colors',[colors(1,:);.5*[1 1 1]],'forceCoefPosFactor',.7)
xlabel('Placement probability')
note=sprintf('N: %i.',sum(not(ismissing(dataRD.probPlacedAny_inverted(sirven)))));
figCell{1,2}=easyExport([dirPlots,'histNoPlacedVsReal_pos',sufix],'displayLatex',false,'caption','Subjective and true placement probability (asking for placement)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 5E  histogram of (subjective risk-actual risk) POSITIVE



figure
compareHistograms({dataRD.riskExpostEnd(sirven)-dataRD.probPlacedAny_inverted(sirven)},...
    'colors',colors,'binedges',-1.05:.1:1.05)
xlabel('Optimism (Subjective - true placement prob.)')

yLim=ylim;
%legendStr=get(legend,'String');

arrowr = annotation('arrow') ;
arrowr.Parent = gca;
arrowr.Position = [0, yLim(2)*.25, .2, 0] ;
hold on
plot([0 0],[0 yLim(2)],'linestyle','--','color',.5*[1 1 1]);

textr = annotation('textbox','String','Optimists','Interpreter','latex','verticalAlignment','middle','edgecolor','none') ;
textr.Parent = gca;
textr.Position = [0, yLim(2)*.3, 1, 0] ;
textr.HorizontalAlignment='left';

%legend(legendStr(1:2))
%set(legend,'String',legendStr(1:2));
hold off

note=sprintf('N: %i.',sum(not(ismissing(dataRD.riskExpostEnd(sirven)-dataRD.probPlacedAny_inverted(sirven)))));

figCell{2,2}=easyExport([dirPlots,'histOptimism_pos',sufix],'displayLatex',false,'caption','Optimism (asking for placement)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);


%% 5F  Binscatter of risk belief (pooled) on actual risk POSITIVE

figure
br1=binsreg(1-dataRD.riskExpostEnd(sirven),1-dataRD.probPlacedAny_inverted(sirven),'wlf',true,'markeredgecolor',colors(1,:),'fitcolor',colors(1,:),'marker','o','posCoeffFit',[.6 .25 .1 .1],'modifyXTicks',false);
ylabel('Subjective placement probability')
xlabel('True placement probability')
hold on
plot([0 1],[0 1],'k:')
xlim([0 1])
ylim([0 1])
set(gca,'xgrid','on')

note=sprintf('N: %i.',sum(not(ismissing(1-dataRD.probPlacedAny_inverted(sirven)))));

figCell{3,2}=easyExport([dirPlots,'binsregDeclaredRealRisk_pos',sufix],'displayLatex',false,'caption','Binscatter of subjective vs true risk (asking for placement)','includeRelativePath',false,'width',widthPlots,'height',heightPlots,'note',note);

subfiguresLatex(figCell,'caption','Subjective, predicted and true first-choice probability, asking for risk and for placement probability (only applicants with positive true risk)','label','figRisks_NegPos','file',[dirPlots,'figRisks_NegPos.tex'],'scale',scalePlots,'erpf','figuresCL/survey2020/');


end


% %% Sync dropbox with Overleaf folder
% if(strcmp(pcName,'felipe'))
% overleafDir='/Users/felipe/Dropbox/Apps/Overleaf/Warnings'' draft/';
% gitDir='/Users/felipe/Dropbox/git/warningsChris/Presentations/Slides_AEA_Jan2021/FiguresSlides/';
% dirPlotsToSync=[gitDir,'/figuresSurvey2020Chi/'];
% system(sprintf('rsync -avzh "%s" "%s" --exclude=".*"',dirPlots,dirPlotsToSync));
% 
% 
% end